/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import model.config.MySQLQuery;
import model.pojo.*;
import model.util.MySQLProviders;
/**
 *
 * @author VuTienIT
 */
public class QuanDAO {
    public static ArrayList<QuanPOJO> getDanhSach(int maKV)
    {
        ArrayList<QuanPOJO> s = new ArrayList<QuanPOJO>();
        MySQLProviders helper = new MySQLProviders();
        helper.open();
        try
        {
            String sql = String.format("Select * From Quan Where MaKhuVuc=%d",maKV);
            ResultSet rs = helper.executeQuery(sql);
            while(rs.next())
            {
                QuanPOJO temp = new QuanPOJO();
                temp.setMaQuan(rs.getInt("MaQuan"));
                temp.setMaKhuVuc(rs.getInt("MaKhuVuc"));
                temp.setTenQuan(rs.getString("TenQuan"));
                s.add(temp);
            }         
        }
        catch(SQLException ex)
        {
            Logger.getLogger(KhachHangPOJO.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            helper.close();
        }
        return s;
    }
    
    public static QuanPOJO getQuan(int maQ)
    {
        QuanPOJO temp = new QuanPOJO();
        MySQLProviders helper = new MySQLProviders();
        helper.open();
        try
        {
            String sql = String.format("Select * From Quan Where MaQuan=%d",maQ);
            ResultSet rs = helper.executeQuery(sql);
            if(rs.next())
            {
                temp.setMaQuan(rs.getInt("MaQuan"));
                temp.setMaKhuVuc(rs.getInt("MaKhuVuc"));
                temp.setTenQuan(rs.getString("TenQuan"));
            }         
        }
        catch(SQLException ex)
        {
            Logger.getLogger(QuanDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        finally
        {
            helper.close();
        }
        return temp;
    }
}
